package ar.edu.utn.frsf.tpae.a2013.g04.persistence.dao.impl;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import ar.edu.utn.frsf.tpae.a2013.g04.persistence.dao.EmpleadoDAO;
import ar.edu.utn.frsf.tpae.a2013.g04.persistence.model.Empleado;

@Component
public class EmpleadoDAOHibernate implements EmpleadoDAO {
	private  SessionFactory  sessionFactory ;
	  
	public  SessionFactory getSessionFactory() {
		return sessionFactory;
	}
    
	@Autowired(required = true)
	public  void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@Override
	public List<Empleado> listar() {
		Session session = sessionFactory.getCurrentSession();
	    Query query = session.createQuery("select emp from Empleado emp");
	    
	    return (List<Empleado>) query.list();
	}

}
